﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using System.Data;
using Common;

namespace VMS_Web
{
    public partial class ViewUnitCodeDetails : System.Web.UI.Page
    {
        #region Intial declaration

                protected MainMaster CurrentMasterPage = null;
                private Master_UnitCode_Types_DB ObjMaster_UnitCode_Types_DB = null;
                

        #endregion
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                
                if (Request["Type"] != null)
                {
                    bindform(Request["Type"].ToString());
                }
                else
                {
                    MessageToDisplay(MessageType.Error, "Oops!Some thing went wrong, contact application support team");
                }
            }
            else
            {
                MessageToDisplay(MessageType.Error, "Oops!Some thing went wrong, contact application support team");
            }

        }
        private void bindform(string unit_code)
        {
            if (ObjMaster_UnitCode_Types_DB == null)
            {
                ObjMaster_UnitCode_Types_DB = new Master_UnitCode_Types_DB();
            }
            DataSet _dataset = new DataSet();
            _dataset = ObjMaster_UnitCode_Types_DB.GetUnitCodeMasterItems(unit_code, "SL");
            if (_dataset.Tables.Count > 0)
            {
                if (_dataset.Tables[0].Rows.Count > 0)
                {
                    txtunitcode.Text = _dataset.Tables[0].Rows[0]["unit_code"].ToString();
                    txtunitcodedesc.Text = _dataset.Tables[0].Rows[0]["Desc"].ToString();
                    chkcustomunit.Checked = Convert.ToBoolean(_dataset.Tables[0].Rows[0]["IsCustomUnit"].ToString());
                    ddlrefunitcode.Text = _dataset.Tables[0].Rows[0]["Ref_UnitCode"].ToString();
                    txtminhours.Text = _dataset.Tables[0].Rows[0]["Min_Hours"].ToString();
                    txtmaxhours.Text = _dataset.Tables[0].Rows[0]["Max_Hours"].ToString();


                }

            }



        }
        private void MessageToDisplay(MessageType messageType, string message)
        {
            if (MessageType.Error == messageType)
            {
                diverror.Attributes["class"] = "alert alert-danger show";
                messagetodisplay.InnerText = message;

            }
            else if (MessageType.Success == messageType)
            {
                diverror.Attributes["class"] = "alert alert-success show";
                messagetodisplay.InnerText = message;
            }
            else if (MessageType.Warning == messageType)
            {
                diverror.Attributes["class"] = "alert alert-warning show";
                messagetodisplay.InnerText = message;
            }
            else if (MessageType.Information == messageType)
            {
                diverror.Attributes["class"] = "alert alert-info show";
                messagetodisplay.InnerText = message;
            }
            else
            {
                diverror.Attributes["class"] = "hidden";
                messagetodisplay.InnerText = "";
            }
        }
    }
}